var tzCourse = {
	timer:null,
	//分页页面的初始化
	initPage:function(itemsCount){
		$(".cpage").tzPage(itemsCount,{
			num_display_entries : 5, //主体页数
			num_edge_entries : 2,//边缘页数
			current_page : 0,//指明选中页码
			items_per_page : 12, //每页显示多条条
			prev_text : "上一页",
			next_text : "下一页",
			showGo:true,//控制是否显示go 页 ,默认是true
			showSelect:true,//控制是否现在下拉框 默认是true
			callback : function(pageNo, pageSize) {//会回传两个参数一个当前页，显示的页数
				tzCourse.loadData(pageNo, pageSize);
			}
		});
	},
	//模板页面的加载
	loadData:function(pageNo, pageSize,callback){
		var keyword = $("#keyword").val();
		var params = {pageNo:pageNo*pageSize,pageSize:pageSize,keyword:keyword};
		var $this = this;
		$.ajax({
			type:"post",
			url:basePath+"/stage/listcourse",
			data:params,
			success:function(data){
				var html = "";
				for(var i = 0;i<data.length;i++){
					var course = data[i];
					html+=" <div class='container'>"+
						"	<div class='film'>"+
						"		<div class='face font'>"+
						"			<img width='222' height='235' src='"+basePath+"/"+course.img+"' alt='"+course.description+"'/>"+
						"		</div>"+
						"		<div class='face back'>" +
						"            <div class='text'>"+course.description+"</div>"+
						"	         <a href='http://www.sxt.cn/course/showdetail-4-one.html'><img width='222' src='"+basePath+"/resources/images/into.gif'/></a>"+
						"	</div>"+
						"	</div>"+
						" </div>";
				}
				$("#tbody").html(html);
				var itemsCount = $("#itemsCount").val();
				$this.highlighter(keyword);
				if(callback)callback(itemsCount);
			}
		});
	},
	//根据关键字搜索
	search:function(){
		var keyword = $("#keyword").val();
		if(isEmpty(keyword)){
			tzMessage.tip("请输入关键字...");
			return;
		}
		tzCourse.loadData(0,12,function(itemsCount){
			tzCourse.initPage(itemsCount);
		});
	},
	//（全局不区分大小写）搜索关键字高亮
	highlighter:function(key){
		$("#tbody").find(".keys").each(function(){
			var text = $(this).text();
			var regexp = new RegExp(key,"ig");//全局替换（不区分大小写）
			var nt = text.replace(regexp,"<span class='red'>"+key+"</span>");
			$(this).html(nt);
		});
	}
};
